package dto

import (
	"time"
	"vrcm/src/vrcm/app/admin/models/live_schedule"
	StreamHubDto "vrcm/src/vrcm/app/admin/service/dto/stream_hub"
	"vrcm/src/vrcm/common/dto"
	common "vrcm/src/vrcm/common/models"
)

type SourceBasicGetPageReq struct {
	dto.Pagination `search:"-"`
	TenantId       string `json:"tenant_id" search:"-"`
	SourceName     string `json:"source_name"  search:"type:contains;column:source_name;table:source_basic"`
	SourceType     int    `json:"source_type"  search:"type:exact;column:source_type;table:source_basic"`
	SourceState    int    `json:"source_state" search:"-"`
	GroupIds       []int  `json:"group_ids" search:"-"`
	IsDelete       int    `json:"is_delete"  search:"type:exact;column:is_delete;table:source_basic"`
	SourceIds      []int  `json:"SourceIds" search:"-"`
	IsShare        int    `json:"is_share" search:"-" comment:"1是带分享的 0，2不带分享"`
	Kind           int    `json:"kind" search:"-"`
}

type SourceBasicOrder struct {
	Id           string `form:"idOrder"  search:"type:order;column:id;table:source_basic"`
	SourceName   string `form:"source_nameOrder"  search:"type:order;column:source_name;table:source_basic"`
	SourceType   string `form:"source_typeOrder"  search:"type:order;column:source_type;table:source_basic"`
	Area         string `form:"areaOrder"  search:"type:order;column:area;table:source_basic"`
	ProtocolType string `form:"protocol_typeOrder"  search:"type:order;column:protocol_type;table:source_basic"`
	StreamType   string `form:"stream_typeOrder"  search:"type:order;column:stream_type;table:source_basic"`
	SourceState  string `form:"source_stateOrder"  search:"type:order;column:source_state;table:source_basic"`
	LiveId       string `form:"live_idOrder"  search:"type:order;column:live_id;table:source_basic"`
	TaskId       string `form:"task_idOrder"  search:"type:order;column:task_id;table:source_basic"`
	Delay        string `form:"delayOrder"  search:"type:order;column:delay;table:source_basic"`
	ActiveItem   string `form:"active_itemOrder"  search:"type:order;column:active_item;table:source_basic"`
	IsDelete     string `form:"is_deleteOrder"  search:"type:order;column:is_delete;table:source_basic"`
	CreateTime   string `form:"create_timeOrder"  search:"type:order;column:create_time;table:source_basic"`
	UpdateTime   string `form:"update_timeOrder"  search:"type:order;column:update_time;table:source_basic"`
	CreateBy     string `form:"createByOrder"  search:"type:order;column:create_by;table:source_basic"`
	UpdateBy     string `form:"updateByOrder"  search:"type:order;column:update_by;table:source_basic"`
}

func (m *SourceBasicGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type SourceBasicInsertReq struct {
	Id               int               `json:"-" comment:""` //
	TenantId         string            `json:"tenant_id" comment:"租户" validate:"required"`
	SourceName       string            `json:"source_name" comment:"信源名称" validate:"required,max=50"`
	EquipNo          string            `json:"equip_no" comment:"设备号"`
	EquipType        int               `json:"equip_type" comment:"设备类型 1 studiolink 2聚合传输设备"`
	ActiveCode       string            `json:"active_code" comment:"激活码"`
	SourceType       int               `json:"source_type" comment:"信源类型 1.网络流 2线下设备"`
	Area             int               `json:"area" comment:"区域1.公网 2内网 3自动调度"`
	ProtocolType     int               `json:"protocol_type" comment:"协议类型1rtmp 2hls 3https 4srt 5udp 6flv 7sdi"`
	StreamType       int               `json:"stream_type" comment:"流类型 1.推流 2拉流 3" `
	Delay            int               `json:"delay" comment:"延迟" validate:"gte=0"`
	ActiveItem       int               `json:"active_item" comment:"当前使用路线 1主 2备 3辅" `
	Details          []SourceDetailDto `json:"details" comment:"信源详情"`
	GroupIds         []int             `json:"group_ids" comment:"信源组id"`
	IsCustom         int               `json:"is_custom" comment:"是否自定义切换 1是 2否"`
	SwitchType       int               `json:"switch_type" comment:"切换类型 1无缝 2有缝"`
	CustomSwitchUrl  string            `json:"custom_switch_url" comment:"自定义切换地址"`
	Kind             int               `json:"kind" comment:"1原始流 2自定义信源 3设备"`
	EnableAutoSwitch int               `json:"enable_auto_switch" comment:"1启用自动切换 2不启用自动切换"`

	PrivateNetworkId int64  `json:"private_network_id" gorm:"type:bigint;comment:专网id"`
	IsAAn            int    `json:"is_aan" gorm:"type:tinyint;comment:全球加速 1开启 2关闭"`
	SourceContent    int    `json:"source_content" gorm:"type:tinyint;comment:信源内容 1sdi矩阵 2SMPTE2110 3NDI"`
	MatrixId         int    `json:"matrix_id" gorm:"type:bigint;comment:矩阵id"`
	SdiPort          int    `json:"sdi_port" gorm:"type:bigint;comment:矩阵端口号"`
	VideoAudio       string `json:"video_audio" gorm:"type:varchar(30);comment:音频视频"`
	VideoSdp         string `json:"video_sdp" gorm:"type:varchar(100);comment:VideoSdp地址"`
	AudioSdp         string `json:"audio_sdp" gorm:"type:varchar(100);comment:AudioSdp地址"`
	AncillarySDP     string `json:"ancillary_sdp" gorm:"type:varchar(1000);comment:AncillarySDP地址"`
	NDIStream        string `json:"ndi_stream" gorm:"type:varchar(100);comment:NDI流"`
	Manufacturer     int    `json:"manufacturer" gorm:"type:bigint;comment:厂家"`
	common.ControlBy
}

type EquipUpdateReq struct {
	Id         int    `json:"id" comment:""` //
	SourceName string `json:"source_name" comment:"信源名称" validate:"required,max=50"`
	EquipNo    string `json:"equip_no" comment:"设备号"`
	common.ControlBy
}

type SourceModelRes struct {
	SourceShare    live_schedule.SourceShare                `json:"source_share" comment:"基本信息"`
	Basic          *live_schedule.SourceBasic               `json:"basic" comment:"基本信息"`
	Details        []live_schedule.SourceDetailModel        `json:"details" comment:"信源详情"`
	Groups         []live_schedule.SourceGroupRelationModel `json:"groups" comment:"信源组"`
	RecordTask     live_schedule.SourceRecordTask           `json:"record_task" comment:"信源录制任务"`
	TransCodeTasks []live_schedule.SourceTemplateModel      `json:"trans_code_tasks" comment:"信源转码任务"`
	IsShare        int                                      `json:"is_share" comment:"1是 0否"`
}

type SourceDetailDto struct {
	Id               int    `json:"id" comment:""` //
	SourceUrl        string `json:"source_url" gorm:"type:varchar(300);comment:信源线路"`
	PushUrl          string `json:"push_url" gorm:"type:varchar(300);comment:信源线路"`
	UrlType          int    `json:"url_type" gorm:"type:tinyint;comment:信源地址类型 1主 2备 3辅 4垫图"`
	IsEnable         int    `json:"is_enable" gorm:"type:tinyint;comment:1启用2禁用"`
	EnableAutoSwitch int    `json:"enable_auto_switch" comment:"1启用自动切换 2不启用自动切换"`
}

func (s *SourceBasicInsertReq) Generate(model *live_schedule.SourceBasic) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	now := time.Now().Unix()
	model.TenantId = s.TenantId
	model.SourceName = s.SourceName
	model.SourceType = s.SourceType
	model.Area = s.Area
	model.ProtocolType = s.ProtocolType
	model.StreamType = s.StreamType
	model.SourceState = 2
	model.SwitchType = s.SwitchType
	model.IsCustom = s.IsCustom
	//model.LiveId = s.LiveId
	//model.TaskId = s.TaskId
	model.Delay = s.Delay
	model.ActiveItem = 1
	model.IsDelete = 2
	model.CreateTime = now
	model.UpdateTime = now
	model.AuditState = 1
	model.Kind = s.Kind
	model.EnableAutoSwitch = s.EnableAutoSwitch
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
	model.EquipNo = s.EquipNo
	model.ActiveCode = s.ActiveCode
	model.EquipType = s.EquipType

	model.PrivateNetworkId = s.PrivateNetworkId
	model.IsAAn = s.IsAAn
	model.SourceContent = s.SourceContent
	model.MatrixId = s.MatrixId
	model.SdiPort = s.SdiPort
	model.VideoAudio = s.VideoAudio
	model.VideoSdp = s.VideoSdp
	model.AudioSdp = s.AudioSdp
	model.AncillarySDP = s.AncillarySDP
	model.NDIStream = s.NDIStream
	model.Manufacturer = s.Manufacturer
}

func (s *SourceBasicInsertReq) GetId() interface{} {
	return s.Id
}

type SourceBasicUpdateReq struct {
	Id         int    `uri:"id" comment:""` //
	TenantId   string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceName string `json:"source_name" comment:"信源名称"`
	//SourceType   int               `json:"source_type" comment:"信源类型 1.网络流 2线下设备"`
	Area int `json:"area" comment:"区域1.公网 2内网"`
	//ProtocolType int               `json:"protocol_type" comment:"协议类型1rtmp 2hls 3https 4srt 5udp 6sdi"`
	StreamType int `json:"stream_type" comment:"流类型 1.推流 2拉流 3"`
	EquipType  int `json:"equip_type" comment:"设备类型 1 studiolink 2聚合传输设备"`
	//SourceState int `json:"source_state" comment:"信源状态 1正常 2停用3 异常 "`
	//LiveId       string            `json:"live_id" comment:"全球直播id"`
	//TaskId       string            `json:"task_id" comment:"任务id"`
	//Delay      int               `json:"delay" comment:"延迟"`
	ActiveCode       string            `json:"active_code" comment:"激活码"`
	ActiveItem       int               `json:"active_item" comment:"当前使用线路 1主 2备 3辅"`
	Details          []SourceDetailDto `json:"details" comment:"信源详情"`
	GroupIds         []int             `json:"group_ids" comment:"信源组id"`
	EnableAutoSwitch int               `json:"enable_auto_switch" comment:"1启用自动切换 2不启用自动切换"`
	TransVdcmUrl     string            `json:"trans_vdcm_url" comment:"转码手动过vdcm的地址"`
	PrivateNetworkId int64             `json:"private_network_id" gorm:"type:bigint;comment:专网id"`
	IsAAn            int               `json:"is_aan" gorm:"type:tinyint;comment:全球加速 1开启 2关闭"`
	SourceContent    int               `json:"source_content" gorm:"type:tinyint;comment:信源内容 1sdi矩阵 2SMPTE2110 3NDI"`
	MatrixId         int               `json:"matrix_id" gorm:"type:bigint;comment:矩阵id"`
	SdiPort          int               `json:"sdi_port" gorm:"type:bigint;comment:矩阵端口号"`
	VideoAudio       string            `json:"video_audio" gorm:"type:varchar(30);comment:音频视频"`
	VideoSdp         string            `json:"video_sdp" gorm:"type:varchar(100);comment:VideoSdp地址"`
	AudioSdp         string            `json:"audio_sdp" gorm:"type:varchar(100);comment:AudioSdp地址"`
	AncillarySDP     string            `json:"ancillary_sdp" gorm:"type:varchar(1000);comment:AncillarySDP地址"`
	NDIStream        string            `json:"ndi_stream" gorm:"type:varchar(100);comment:NDI流"`
	Manufacturer     int               `json:"manufacturer" gorm:"type:bigint;comment:厂家"`
	common.ControlBy
}

func (s *SourceBasicUpdateReq) Generate(model *live_schedule.SourceBasic) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	now := time.Now().Unix()
	model.TenantId = s.TenantId
	model.SourceName = s.SourceName
	//model.SourceType = s.SourceType
	model.Area = s.Area
	//model.ProtocolType = s.ProtocolType
	model.StreamType = s.StreamType
	model.EquipType = s.EquipType
	//model.SourceState = s.SourceState
	//model.Delay = s.Delay
	model.ActiveItem = s.ActiveItem
	model.IsDelete = 2
	model.UpdateTime = now
	model.EnableAutoSwitch = s.EnableAutoSwitch
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
	if len(s.TransVdcmUrl) > 0 {
		model.IsShow = 1
		model.OutUdpUrl = s.TransVdcmUrl
	}
	model.ActiveCode = s.ActiveCode
	model.PrivateNetworkId = s.PrivateNetworkId
	model.IsAAn = 2
	model.SourceContent = s.SourceContent
	model.MatrixId = s.MatrixId
	model.SdiPort = s.SdiPort
	model.VideoAudio = s.VideoAudio
	model.VideoSdp = s.VideoSdp
	model.AudioSdp = s.AudioSdp
	model.AncillarySDP = s.AncillarySDP
	model.NDIStream = s.NDIStream
	model.Manufacturer = s.Manufacturer
}

func (s *SourceBasicUpdateReq) GetId() interface{} {
	return s.Id
}

// SourceBasicGetReq 功能获取请求参数
type SourceBasicGetReq struct {
	Id int `uri:"id"`
}

type SourceBasicGetRes struct {
	SourceBasic      *live_schedule.SourceBasic          `json:"source_basic" comment:"信源基本信息" `
	SourceGroup      *[]live_schedule.SourceGroup        `json:"source_group" comment:"信源组" `
	SourceDetails    []live_schedule.SourceDetailModel   `json:"source_details" comment:"信源详情"`
	TransCodeTasks   []live_schedule.SourceTemplateModel `json:"trans_code_tasks" comment:"转码信源详情"`
	SourceRecordTask live_schedule.SourceRecordTask      `json:"source_record_task" comment:"信源录制任务"`
}

func (s *SourceBasicGetReq) GetId() interface{} {
	return s.Id
}

// SourceBasicDeleteReq 功能删除请求参数
type SourceBasicDeleteReq struct {
	Ids []int `json:"id"`
}

type SourceTransDeleteReq struct {
	Id          int    `json:"id"`
	TransTaskId string `json:"trans_task_id"`
}

type SourceDeleteReq struct {
	Id int `json:"id"`
}

func (s *SourceBasicDeleteReq) GetId() interface{} {
	return s.Ids
}

type StartSourceReq struct {
	Id       int    `json:"id" comment:"" validate:"required"` //
	TenantId string `json:"tenant_id" comment:"租户" validate:"required"`
	//TaskId   string `json:"task_id" comment:"任务id"`
}

type StopSourceReq struct {
	Id       int    `json:"id" comment:"" validate:"required"` //
	TenantId string `json:"tenant_id" comment:"租户" validate:"required"`
	TaskId   string `json:"task_id" comment:"任务id"`
}

type ChangeSourceReq struct {
	Id            int    `json:"id" comment:"信源id" validate:"required"`        //
	TaskId        string `json:"task_id" comment:"信源任务id" validate:"required"` //
	TransRecordId int    `json:"trans_record_id" comment:"转码任务id"`             //
	TenantId      string `json:"tenant_id" comment:"租户" validate:"required"`
	ActiveItem    int    `json:"active_item" comment:"当前输出项 1主 2备 3辅 4垫" validate:"gt=0"`
	//StreamType    int    `json:"stream_type" comment:"信源类型 1原始 2转码"`
	TemplateId  string `json:"template_id" comment:"模版id"`
	TransTaskId string `json:"trans_task_id" comment:"转码任务记录id"` //
}

type SourceCallBackReq struct {
	Id                          string  `json:"id" comment:"主任务id" validate:"required"`     //
	TaskId                      string  `json:"taskId" comment:"子任务id" validate:"required"` //
	TransferState               string  `json:"transferState" comment:"任务状态" validate:"required"`
	TransferStateLastUpdateTime float64 `json:"transferStateLastUpdateTime" comment:"任务更新时间" validate:"required"`
}

type GetShareSourceConfig struct {
	TenantId string `json:"tenant_id" comment:"租户"  validate:"required"`
	SourceId int    `json:"source_id" comment:"信源id"  validate:"required"`
}

type GetShareSourcesReq struct {
	dto.Pagination `search:"-"`
	TenantId       string `json:"tenant_id" search:"-" comment:"租户" validate:"required"`
	SourceName     string `json:"source_name"  search:"type:contains;column:source_name;table:source_basic"`
	SourceType     int    `json:"source_type"  search:"type:exact;column:source_type;table:source_basic"`
	SourceState    int    `json:"source_state"  search:"type:exact;column:source_state;table:source_basic"`
	GroupIds       []int  `json:"group_ids" search:"-"`
	IsDelete       int    `json:"is_delete"  search:"type:exact;column:is_delete;table:source_basic"`
}

type ShareSourceConfigUpdateReq struct {
	Id        int      `json:"id" comment:"信源分享配置id" validate:"required"` //
	TenantId  string   `json:"tenant_id" comment:"租户"  validate:"required"`
	SourceId  int      `json:"source_id" comment:"信源id" validate:"required"`
	IsEnable  int      `json:"is_enable" comment:"是否开启 1开启 2未开启" validate:"gt=0"`
	ShareType int      `json:"share_type" comment:"分享类型 1公开 2部分公开"`
	Accounts  []string `json:"accounts" comment:"分享的账户"`
	common.ControlBy
}

type ShareSourceRemarkUpdateReq struct {
	Id     int    `json:"id" comment:"信源分享配置id" validate:"required"` //
	Remark string `json:"remark" comment:"评论"`
	common.ControlBy
}

func (s *ShareSourceConfigUpdateReq) Generate(model *live_schedule.ShareSourceConfig) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.TenantId = s.TenantId
	model.SourceId = s.SourceId
	model.IsEnable = s.IsEnable
	model.ShareType = s.ShareType
	model.UpdateTime = time.Now().Unix()
	model.UpdateBy = s.UpdateBy
}

func (s *ShareSourceConfigUpdateReq) GetId() interface{} {
	return s.Id
}

type ShareSourceConfigModel struct {
	ShareSourceConfig live_schedule.ShareSourceConfig `json:"share_source_config" comment:"分享配置信息"`
	Accounts          []string                        `json:"accounts" comment:"分享的账户"`
}

type GetSourcesStatistics struct {
	TenantId string `json:"tenant_id" comment:"租户"`
}

type SourcesStatistic struct {
	TotalCount  int `json:"total_count" comment:"总数"`
	NormalCount int `json:"normal_count" comment:"正常数"`
	FailCount   int `json:"fail_count" comment:"异常数"`
	OffCount    int `json:"off_count" comment:"下线数"`
}

type GetSourceTaskPageReq struct {
	TenantId       string `json:"tenant_id" comment:"租户"   search:"type:exact;column:tenant_id;table:source_template"`
	SourceIds      []int  `json:"source_id" comment:"信源id"  search:"-"`
	TemplateId     string `json:"template_id" comment:"转码模版id" search:"-"`
	TransTaskId    string `json:"trans_task_id" comment:"转码任务id" search:"-"`
	dto.Pagination `search:"-"`
}

func (m *GetSourceTaskPageReq) GetNeedSearch() interface{} {
	return *m
}

type CreateSourceTaskReq struct {
	Id                  int                          `json:"id" comment:"转码任务ID"`
	TenantId            string                       `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId            int                          `json:"source_id" comment:"信源id" validate:"required"`
	TaskName            string                       `json:"task_name" comment:"任务名称" validate:"required"`
	IsCustom            int                          `json:"is_custom" comment:"是否自定义 1是 2否"`
	CustomTransCodeUrls []CustomTransCodeUrl         `json:"custom_trans_code_urls" comment:"自定义转码地址"`
	SourceDetails       []live_schedule.SourceDetail `json:"source_details" comment:"信源详情"`
	IsCustomSwitch      int                          `json:"is_custom_switch" comment:"是否自定义切换地址 1是 2否"`
	CustomSwitchUrl     string                       `json:"custom_switch_url" comment:"自定义切换地址"`
	Template            StreamHubDto.Template        `json:"template" comment:"模版信息"`
	Advanced            StreamHubDto.Advanced        `json:"advanced" comment:"转码高级配置"`
	EnableAdvance       int                          `json:"enable_advance" comment:"启用高级配置 1是 2否"`
	SchedulerMode       string                       `json:"scheduler_mode" comment:"设备模式"`
	ServiceLoadId       string                       `json:"service_load_id" comment:"设备id"`
}

type CreateTranscodeReq struct {
	TenantId           string                `json:"tenant_id" comment:"租户" validate:"required"`
	TaskName           string                `json:"task_name" comment:"任务名称"`
	IsCustom           int                   `json:"is_custom" comment:"是否自定义 1是 2否"`
	CustomTransCodeUrl string                `json:"custom_trans_code_url" comment:"自定义转码地址"`
	Template           StreamHubDto.Template `json:"template" comment:"模版信息"`
}

type Template struct {
	TemplateId   string `json:"templateId"`
	Acodec       string `json:"acodec"`
	AudioBitrate int    `json:"audioBitrate"`
	Vcodec       string `json:"vcodec"`
	VideoBitrate int    `json:"videoBitrate"`
	Width        int    `json:"width"`
	Height       int    `json:"height"`
	Fps          int    `json:"fps"`
	Gop          int    `json:"gop"`
	Profile      string `json:"profile"`
}
type TransCodeUrl struct {
	UrlType int    `json:"url_type" comment:"类型 1主 2备 3辅"`
	Url     string `json:"url" comment:"url"`
}

type CustomTransCodeUrl struct {
	UrlType   int    `json:"url_type" comment:"类型 1主 2备 3辅"`
	CustomUrl string `json:"custom_url" comment:"自定义url"`
}

type UpdateTransCodeTaskReq struct {
	Id       int    `json:"id" comment:"任务id"`
	TaskName string `json:"task_name" comment:"任务名称" validate:"required"`
}

type StarTransCodTaskReq struct {
	Id         int    `json:"id" comment:"主任务id" validate:"required"`
	TenantId   string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId   int    `json:"source_id" comment:"信源id" validate:"required"`
	TaskId     string `json:"task_id" comment:"子任务id" validate:"required"` //
	TemplateId string `json:"template_id" comment:"模版id" validate:"required"`
}

type StopTransCodTaskReq struct {
	Id         int    `json:"id" comment:"主任务id" validate:"required"`
	TenantId   string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId   int    `json:"source_id" comment:"信源id" validate:"required"`
	TaskId     string `json:"task_id" comment:"子任务id" validate:"required"` //
	TemplateId string `json:"template_id" comment:"模版id" validate:"required"`
}

type DeleteSourceTaskReq struct {
	Id         int    `json:"id" comment:"主任务id" validate:"required"`
	TaskId     string `json:"task_id" comment:"子任务id" validate:"required"` //
	TenantId   string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId   int    `json:"source_id" comment:"信源id" validate:"required"`
	TemplateId string `json:"template_id" comment:"模版id" validate:"required"`
}

type TransCodeCallBackReq struct {
	Id                          string  `json:"id" comment:"主任务id" validate:"required"`     //
	TaskId                      string  `json:"taskId" comment:"子任务id" validate:"required"` //
	TransferState               string  `json:"transferState" comment:"任务状态" validate:"required"`
	TransferStateLastUpdateTime float64 `json:"transferStateLastUpdateTime" comment:"任务更新时间" validate:"required"`
}

type StartSourceRecordReq struct {
	TenantId string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId int    `json:"source_id" comment:"信源id" validate:"required"`
}

type StopSourceRecordReq struct {
	TenantId string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId int    `json:"source_id" comment:"信源id" validate:"required"`
}

type RecordFileCallBack struct {
	TaskId    string `json:"taskId"`
	FileId    string `json:"id"`
	LiveId    string `json:"liveId"`
	Path      string `json:"path"`
	Tag       string `json:"tag"`
	StartTime string `json:"startTime"`
	EndTIme   string `json:"endTIme"`
	Duration  string `json:"duration"`
}

type SourceRecordGetPageReq struct {
	dto.Pagination `search:"-"`
	TenantId       string `json:"tenant_id" comment:"租户"  search:"type:exact;column:tenant_id;table:source_record""`
	SourceName     string `json:"source_name"  search:"type:contains;column:source_name;table:source_record"`
	SourceId       int    `json:"source_id"  search:"type:exact;column:source_id;table:source_record"`
	StartTime      int    `json:"start_time"  search:"-"`
	EndTime        int    `json:"end_time"  search:"-"`
}

type SourceRecordDeleteReq struct {
	Id int `json:"id"`
}

func (m *SourceRecordGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type GetSourceRecordReq struct {
	SourceId int `uri:"source_id" validate:"required"`
}
type GetAuditResultBySourceReq struct {
	ChannelId int `json:"channel_id" comment:"频道id""`
	SourceId  int `json:"source_id"`
}
type GetAuditResultDetailBySourceReq struct {
	dto.Pagination `search:"-"`
	SourceId       int   `json:"source_id" validate:"required"`
	ViolationType  []int `json:"violation_type" comment:"违规类型 1色情识别、2暴力、3恶心、4广告、5政治敏感 6其他"`
}

type UpdateAuditState struct {
	TenantId   string `json:"tenant_id" comment:"租户" validate:"required"`
	SourceId   int    `json:"source_id" validate:"required"`
	AuditState int    `json:"audit_state" comment:"1通过 2不通过 3审核中"`
	//TaskIds    []string `json:"task_ids" comment:"审核任务id"` //
}

type GetAuditState struct {
	TenantId string `json:"tenant_id" comment:"租户"`
	SourceId int    `json:"source_id" validate:"required"`
}

type AutoSwitchReq struct {
	SwitchId    string `json:"id" comment:"切换id" validate:"required"`
	ActiveIndex int    `json:"inputActiveIndex" comment:"切换索引"`
}

type GetEquipByCode struct {
	EquipCode string `json:"equip_code"`
}

type EquipBeatReq struct {
	EquipCode string `json:"equip_code"`
}

type EquipCallBack struct {
	EquipCode  string `json:"equip_code"`
	EquipState int    `json:"equip_state" comment:"1在线 2离线"`
}

type SaveSourceBasicNewReq struct {
	Id               int    `json:"id" gorm:"type:bigint;comment:租户id"`
	TenantId         string `json:"tenant_id" gorm:"type:varchar(50);comment:租户id"`
	SourceName       string `json:"source_name" gorm:"type:varchar(50);comment:信源名称"`
	SourceType       int    `json:"source_type" gorm:"type:tinyint;comment:信源类型 1.网络流 2线下设备"`
	Area             int    `json:"area" gorm:"type:tinyint;comment:区域1.公网 2内网"`
	ProtocolType     int    `json:"protocol_type" gorm:"type:tinyint;comment:协议类型1rtmp 2hls 3https 4srt 5udp 6sdi"`
	StreamType       int    `json:"stream_type" gorm:"type:tinyint;comment:流类型 1.推流 2拉流 3"`
	SourceState      int    `json:"source_state" gorm:"type:tinyint;comment:信源状态 1启用 2停用3 异常"`
	TaskId           string `json:"task_id" gorm:"type:varchar(100);comment:任务id"`
	OutUdpUrl        string `json:"out_udp_url" gorm:"type:varchar(300);comment:输出源udp地址"`
	IsDelete         int    `json:"is_delete" gorm:"type:tinyint;comment:是否删除 1删除 2未删除"`
	StartTime        int64  `json:"start_time" gorm:"type:int;comment:上一次起用时间"`
	StopTime         int64  `json:"stop_time" gorm:"type:int;comment:上一次停用时间"`
	PrivateNetworkId int64  `json:"private_network_id" gorm:"type:bigint;comment:专网id"`
	IsAAn            int    `json:"is_aan" gorm:"type:tinyint;comment:全球加速 1开启 2关闭"`
	SourceContent    int    `json:"source_content" gorm:"type:tinyint;comment:信源内容 1sdi矩阵 2SMPTE2110 3NDI"`
	MatrixId         int    `json:"matrix_id" gorm:"type:bigint;comment:矩阵id"`
	SdiPort          int    `json:"sdi_port" gorm:"type:bigint;comment:矩阵端口号"`
	VideoAudio       string `json:"video_audio" gorm:"type:varchar(30);comment:音频视频"`
	VideoSdp         string `json:"video_sdp" gorm:"type:varchar(100);comment:VideoSdp地址"`
	AudioSdp         string `json:"audio_sdp" gorm:"type:varchar(100);comment:AudioSdp地址"`
	AncillarySDP     string `json:"ancillary_sdp" gorm:"type:varchar(1000);comment:AncillarySDP地址"`
	NDIStream        string `json:"ndi_stream" gorm:"type:varchar(100);comment:NDI流"`
	SourceUrl        string `json:"source_url" gorm:"type:varchar(300);comment:信源地址"`
}

func (s *SaveSourceBasicNewReq) Generate(model *live_schedule.SourceBasicNew) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	now := time.Now().Unix()
	model.TenantId = s.TenantId
	model.SourceName = s.SourceName
	model.SourceType = s.SourceType
	model.Area = s.Area
	model.ProtocolType = s.ProtocolType
	model.StreamType = s.StreamType
	model.SourceState = 2
	model.IsDelete = 2
	model.StartTime = 0
	model.StopTime = 0
	model.PrivateNetworkId = 0
	model.IsAAn = 2
	model.SourceContent = s.SourceContent
	model.MatrixId = s.MatrixId
	model.SdiPort = s.SdiPort
	model.VideoAudio = s.VideoAudio
	model.VideoSdp = s.VideoSdp
	model.AudioSdp = s.AudioSdp
	model.AncillarySDP = s.AncillarySDP
	model.NDIStream = s.NDIStream
	model.SourceUrl = s.SourceUrl
	if s.Id <= 0 {
		model.CreateTime = now
		model.UpdateTime = now
	} else {
		model.UpdateTime = now
	}

}

type DelSourceBasicNewReq struct {
	Id int `json:"id" gorm:"type:bigint;comment:租户id"`
}

type GetSourceBasicNewReq struct {
	Id int `json:"id" gorm:"type:bigint;comment:租户id"`
}

type SourceBasicNewGetPageReq struct {
	dto.Pagination `search:"-"`
	TenantId       string `json:"tenant_id" search:"-"`
	SourceName     string `json:"source_name"  search:"type:contains;column:source_name;table:source_basic"`
	SourceType     int    `json:"source_type"  search:"type:exact;column:source_type;table:source_basic"`
	SourceState    int    `json:"source_state" search:"-"`
}

func (m *SourceBasicNewGetPageReq) GetNeedSearch() interface{} {
	return *m
}
